import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// import { visualizer } from 'rollup-plugin-visualizer'
import path from "path";
import themeConfig from "./config/theme";
import eslintPlugin from "vite-plugin-eslint";
import { createHtmlPlugin } from "vite-plugin-html";

const target = "https://blade-gateway.zhaojiafang.com";
// const target = " http:/192.168.124.31:8882";
// https://vitejs.dev/config/
export default defineConfig({
	//分析依赖产物
	//plugins: [react(), visualizer() ],
	define: {
		eval: "window.eval",
		__APP_TITLE__: JSON.stringify("找家纺"),
		__INDUSTRIAL_BELT_FLAG__: 0
	},
	plugins: [
		react(),
		eslintPlugin(),
		createHtmlPlugin({
			inject: {
				data: {
					title: "找家纺ERP",
					favicon: "/favicon-erp.png"
				}
			}
		})
	],
	resolve: {
		alias: {
			"@": path.resolve(__dirname, "./src")
		},
		extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"]
	},
	css: {
		preprocessorOptions: {
			less: {
				modifyVars: {
					...themeConfig
				},
				javascriptEnabled: true
			}
		}
	},
	build: {
		minify: "terser",
		terserOptions: {
			compress: {
				drop_console: true,
				drop_debugger: true
				// dead_code: true
			}
		},
		reportCompressedSize: false,
		rollupOptions: {
			output: {
				chunkFileNames: "js/[name]-[hash].js",
				entryFileNames: "js/[name]-[hash].js",
				assetFileNames: "[ext]/[name].[ext]"
			}
		}
	},
	server: {
		port: 9000,
		hmr: {
			overlay: true
		},
		proxy: {
			"/blade": {
				// '/api'是代理标识，用于告诉node，url前面是/api的就是使用代理的
				target: target,
				//目标地址，一般是指后台服务器地址
				// target: "http://localhost:8099", //目标地址，一般是指后台服务器地址
				changeOrigin: true //是否跨域
			},
			"/zjf": {
				// '/api'是代理标识，用于告诉node，url前面是/api的就是使用代理的
				target: target,
				//目标地址，一般是指后台服务器地址
				// target: "http://localhost:8099", //目标地址，一般是指后台服务器地址
				changeOrigin: true //是否跨域
			}
		}
	},
	preview: {
		port: 3000
	}
});
